package cn.yj.supports;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * 消息成功投递到交换机上的回调
 * 成功投递到交换机，不代表入队成功
 *
 * @author 永健
 * @since 2022-02-09 10:06
 */
public class RabbitConfirmCallback implements RabbitTemplate.ConfirmCallback {
    private static final Logger log = LoggerFactory.getLogger(RabbitConfirmCallback.class);

    /**
     * Confirmation callback.
     *
     * @param correlationData correlation data for the callback.
     * @param ack             true for ack, false for nack
     * @param cause           An optional cause, for nack, when available, otherwise null.
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.info("消息投递结果:ack={},cause={}", ack, cause);
        if(correlationData!=null){
            log.info(correlationData.getReturnedMessage().toString());
        }
    }
}
